import Vue from 'vue'
import VueRouter from 'vue-router'
import auth from '@/utils/token'
import { Message } from 'element-ui'
import Appp from '@/appp/zxcvb.vue'
const Login = () => import('@/views/login')
const Layout = () => import('@/views/Layout.vue')
const Home = () => import('@/views/home')
const Article = () => import('@/views/article')
const Publish = () => import('@/views/publish')
Vue.use(VueRouter)
const router = new VueRouter({
  routes: [
    { path: '/login', component: Login },
    {
      path: '/',
      component: Layout,
      children: [
        { path: '', component: Home },
        { path: 'article', component: Article },
        { path: 'publish', component: Publish },
        { path: 'publish/:id', component: Publish },
        { path: 'appp', component: Appp }

      ]
    }
  ]
})
router.beforeEach((to, from, next) => {
  const token = auth.getToken()
  if (to.path !== '/login' && !token) {
    Message.error('登录信息失效')
    return next('/login')
  }
  next()
})
export default router
